import 'package:xvideos/hj_model/home/video_list_resp.dart';
import 'package:xvideos/hj_model/video_model.dart';
import 'package:xvideos/hj_utils/http_manager.dart';

class TagService {
  static Future<TagsBean?> fetchTagInfo(String? tagId) async {
    final param = <String, dynamic>{'tagID': tagId};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/tag/info', param: param, jsonTransformation: (json) => TagsBean.fromMap(json));
    return result.data;
  }

  /// 获取首页发布的tag
  static Future<List<TagsBean>> fetchHomePublishTags({int page = 1}) async {
    final result = await httpManager.fetchResponseByGET('/tag/list/pub',
        param: <String, dynamic>{'pageNumber': page, 'pageSize': 20},
        jsonTransformation: (json) => (json['list'] as List?)?.map((e) => TagsBean.fromMap(e)).toList() ?? []);
    return result.data;
  }

  /// 标签详情拉去视频数据
  ///sortType  1、推荐，2、最新，3、最热 4、精华，5、视频
  static Future<VideoListResp?> fetchTagList(String? tagId,
      {int? sortType, int page = 1, int size = 10, String? newsType, String? sortBy, int? videoType}) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'sortType': sortType,
      'tagID': tagId,
      'newsType': newsType,
      'sortBy': sortBy,
      'videoType': videoType
    };
    param.removeWhere((key, value) => value == null);
    final result =
        await httpManager.fetchResponseByGET('/tag/vid/list', param: param, jsonTransformation: (json) => VideoListResp.fromJson(json));
    return result.data;
  }

  ///sortType  1、推荐，2、最新，3、最热 4、精华，5、视频
  static Future<VideoListResp?> fetchShortTagList(String? tagId,
      {int? sortType, int page = 1, int size = 10, String? newsType, String? sortBy, int? videoType}) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'sortType': sortType,
      'tagID': tagId,
      'newsType': newsType,
      'sortBy': sortBy,
      'videoType': videoType
    };
    param.removeWhere((key, value) => value == null);
    final result =
        await httpManager.fetchResponseByGET('/tag/short/list', param: param, jsonTransformation: (json) => VideoListResp.fromJson(json));
    return result.data;
  }

  /// 树洞发布纸条
  static Future<bool?> treeHolePostNote(
    String content,
    int type, {
    List<String>? images,
  }) async {
    final param = <String, dynamic>{
      'content': content,
      'type': type,
      'images': images,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByPOST('/driftBottle/publisher', param: param);
    return result.isSuccess;
  }
}
